﻿#nullable disable
using Android.Hardware.Camera2;

namespace Camera2Demo
{
    internal class CameraDeviceStateCallback : CameraDevice.StateCallback
    {
        private readonly Awaiter _awaiter = new Awaiter();
        public CameraDevice CameraDevice { get; set; }
        public CameraError Error { get; set; }
        public bool IsCompleted { get; private set; }
        public bool IsError { get; set; }
        public bool IsOpened { get; set; }

        public Awaiter GetAwaiter()
        {
            return _awaiter;
        }

        public override void OnDisconnected(CameraDevice camera)
        {
            IsOpened = false;
        }

        public override void OnError(CameraDevice camera, CameraError error)
        {
            IsError = true;
            Error = error;
            _awaiter.Completed();
        }

        public override void OnOpened(CameraDevice camera)
        {
            IsOpened = true;
            CameraDevice = camera;
            _awaiter.Completed();
        }
    }
}